package com.apexsoft.assets.base.request;


import lombok.NoArgsConstructor;

import java.util.LinkedList;
import java.util.List;

/**
 * 存储每次请求时，调用的方法，sql和入参
 */
@NoArgsConstructor
public class RequestInfoModel {
    private String uuid;
    private String userID;
    private String methodName;
    private String paramStr;
    private String ip;
    private Integer type = 0;
    private String msg  ;
    private long duration;
    private long rows;
    private List<String> sqlList;

    public String getSqlListStr() {
        StringBuffer sb = new StringBuffer();
        if(sqlList == null || sqlList.isEmpty()){
            return sb.toString();
        }
        for (int i = 0;i<sqlList.size();){
            sb.append(sqlList.get(i));
            i++;
            if(i<sqlList.size()){
                sb.append(";");
            }
        }
        return sb.toString();
    }

    public RequestInfoModel addSql(String sql){
        if(sqlList == null){
            sqlList = new LinkedList<>();
        }
        sqlList.add(sql);
        return this;
    }

    @Override
    public String toString() {
        return "RequestInfoModel{" +
                "uuid='" + uuid + '\'' +
                ", userID='" + userID + '\'' +
                ", methodName='" + methodName + '\'' +
                ", paramStr='" + paramStr + '\'' +
                ", ip='" + ip + '\'' +
                ", type=" + type +
                ", msg='" + msg + '\'' +
                ", duration=" + duration +
                ", rows=" + rows +
                ", sqlList=" + getSqlListStr() +
                '}';
    }

    public long getRows() {
        return rows;
    }

    public RequestInfoModel setRows(long rows) {
        this.rows = rows;
        return this;
    }

    public String getUuid() {
        return uuid;
    }

    public RequestInfoModel setUuid(String uuid) {
        this.uuid = uuid;
        return this;
    }

    public String getUserID() {
        return userID;
    }

    public RequestInfoModel setUserID(String userID) {
        this.userID = userID;
        return this;
    }

    public String getMethodName() {
        return methodName;
    }

    public RequestInfoModel setMethodName(String methodName) {
        this.methodName = methodName;
        return this;
    }

    public String getParamStr() {
        return paramStr;
    }

    public RequestInfoModel setParamStr(String paramStr) {
        this.paramStr = paramStr;
        return this;
    }

    public String getIp() {
        return ip;
    }

    public RequestInfoModel setIp(String ip) {
        this.ip = ip;
        return this;
    }

    public Integer getType() {
        return type;
    }

    public RequestInfoModel setType(Integer type) {
        this.type = type;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public RequestInfoModel setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public long getDuration() {
        return duration;
    }

    public RequestInfoModel setDuration(long duration) {
        this.duration = duration;
        return this;
    }

    public List<String> getSqlList() {
        return sqlList;
    }

    public RequestInfoModel setSqlList(List<String> sqlList) {
        this.sqlList = sqlList;
        return this;
    }
}
